{
    "cells": [
  {
   "cell_type": "markdown",
   "id": "4262e2f2",
   "metadata": {},
   "source": [
    "# KISS-ICP running on the KITTI-Odometry benchmark dataset\n",
    "\n",
    "The whole purpose of this notebook is to have a reproducable entry point for the experiments of the paper. You can also modify the system and just run this notebook to inspect the overall results\n",
    "\n",
    "## Expected dataset layout\n",
    "\n",
    "```\n",
    "<data/kitti-odometry/dataset>\n",
    "├── poses\n",
    "│   ├── 00.txt\n",
    "│   ├── 01.txt\n",
    "│   ├── 02.txt\n",
    "│   ├── 03.txt\n",
    "│   ├── 04.txt\n",
    "│   ├── 05.txt\n",
    "│   ├── 06.txt\n",
    "│   ├── 07.txt\n",
    "│   ├── 08.txt\n",
    "│   ├── 09.txt\n",
    "│   ├── 10.txt\n",
    "└── sequences\n",
    "    ├── 00\n",
    "    │   ├── calib.txt\n",
    "    │   ├── poses.txt\n",
    "    │   ├── times.txt\n",
    "    │   └── velodyne\n",
    "    ├── 01\n",
    "    │   ├── ....\n",
    "\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50ef1421",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Install KISS-ICP and Plotting tools\n",
    "%pip install kiss-icp ipympl evo >/dev/null\n",
    "\n",
    "import os\n",
    "\n",
    "import kiss_icp\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from evo.tools import plot\n",
    "from kiss_icp.datasets import dataset_factory\n",
    "from kiss_icp.pipeline import OdometryPipeline\n",
    "\n",
    "%autoreload 2\n",
    "%matplotlib inline\n",
    "%matplotlib widget"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0e7c52d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_root = os.environ.get(\"DATASETS\")\n",
    "kitti_root = os.path.join(data_root, \"kitti-odometry/dataset\")\n",
    "print(f\"Reading datasets from : {data_root}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "882e36f3",
   "metadata": {},
   "source": [
    "## Run all sequences on the dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd62b33e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from kiss_icp_eval import run_sequence\n",
    "\n",
    "\n",
    "def kitti_sequence(sequence: int):\n",
    "    return OdometryPipeline(\n",
    "        dataset=dataset_factory(\n",
    "            dataloader=\"kitti\",\n",
    "            data_dir=kitti_root,\n",
    "            sequence=sequence,\n",
    "        )\n",
    "    )\n",
    "\n",
    "\n",
    "results = {}\n",
    "for sequence in range(0, 11):\n",
    "    run_sequence(kitti_sequence, sequence=sequence, results=results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d67cb048",
   "metadata": {},
   "outputs": [],
   "source": [
    "from kiss_icp_eval import print_metrics_table\n",
    "\n",
    "print_metrics_table(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbc9fc28",
   "metadata": {},
   "source": [
    "## Trajectories Results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d0d4a21",
   "metadata": {},
   "outputs": [],
   "source": [
    "from kiss_icp_eval import plot_trajectories\n",
    "\n",
    "plot_trajectories(results)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  },
  "vscode": {
   "interpreter": {
    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
